package logic

import (
	"context"
	"elem_svc/models/mysql"

	"elem_svc/elem"
	"elem_svc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ShopListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewShopListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ShopListLogic {
	return &ShopListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 商家列表
func (l *ShopListLogic) ShopList(in *elem.ShopListRequest) (*elem.ShopListResponse, error) {
	// todo: add your logic here and delete this line

	var shops []mysql.Shop
	mysql.DB.Debug().Find(&shops)

	var shopList []*elem.ShopList
	for _, shop := range shops {
		list := elem.ShopList{
			Name:     shop.Name,
			Slice:    int64(shop.Slice),
			Sales:    int64(shop.Sales),
			Distance: shop.Distance,
			Address:  shop.Address,
			Status:   shop.Status,
		}
		shopList = append(shopList, &list)
	}

	return &elem.ShopListResponse{
		List: shopList,
	}, nil
}
